// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ByteBufferObjectFactory.java

package org.quickserver.util.pool;

import java.nio.ByteBuffer;
import org.apache.commons.pool.BasePoolableObjectFactory;

public class ByteBufferObjectFactory extends BasePoolableObjectFactory
{

    public ByteBufferObjectFactory(int bufferSize, boolean useDirectByteBuffer)
    {
        this.bufferSize = -1;
        this.useDirectByteBuffer = true;
        this.bufferSize = bufferSize;
        this.useDirectByteBuffer = useDirectByteBuffer;
    }

    public Object makeObject()
    {
        if(useDirectByteBuffer)
            return ByteBuffer.allocateDirect(bufferSize);
        else
            return ByteBuffer.allocate(bufferSize);
    }

    public void passivateObject(Object obj)
    {
        ByteBuffer ch = (ByteBuffer)obj;
        ch.clear();
    }

    public void activateObject(Object obj1)
    {
    }

    public void destroyObject(Object obj)
    {
        if(obj == null)
        {
            return;
        } else
        {
            passivateObject(obj);
            obj = null;
            return;
        }
    }

    public boolean validateObject(Object obj)
    {
        return obj != null;
    }

    int bufferSize;
    boolean useDirectByteBuffer;
}
